/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package domoticus;

import java.awt.Color;
import java.awt.Component;
import java.awt.GridBagConstraints;
import java.awt.GridLayout;
import java.awt.Image;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ItemEvent;
import java.util.List;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.Timer;

/**
 *
 * @author Samunake
 */
public class VentanaPrincipal extends javax.swing.JFrame {

    MicroControler uc;
    String sensorType = null;
    static String room;
    BeginPanelData init;
    private Timer timer;
    private Integer time;
    private Integer timeCopia;
    private Timer timetask;
    List<String> sensors;
    List<String> datasensor;
    javax.swing.JLabel sensorValue;

    public VentanaPrincipal() {
        initComponents();
        time = timeSlider.getValue();
        timeLabel.setText("Actualizacion de datos cada " + time / 1000 + " s");
        init = new BeginPanelData();
        roomPanel.add(init);
        sensorPanel.setVisible(false);
        init.setVisible(true);
        dataPanel.setVisible(false);
        ActuatorsPanel.setVisible(false);
        this.setIconImage(new ImageIcon(getClass().getResource("/img/icono4.png")).getImage());
        addRoms();
    }

    public List<String> getRoms() {
        uc = new MicroControler();
        return uc.getRooms();

    }

    public List<String> getStreams(String room) {
        uc = new MicroControler();
        return uc.getSensors(room);

    }

    private void addRoms() {
        List<String> rooms = getRoms();
        for (String r : rooms) {
            comboRooms.addItem(r);
        }
    }

    public String selectedRoom() {

        this.room = String.valueOf(comboRooms.getSelectedItem());
        return room;

    }

    private void actualiza(javax.swing.JPanel p) {
        p.removeAll();
        p.updateUI();
    }

    private void ejecutaActualiza() {
        actualiza(sensorPanel);
        actualiza(jPanel6);
        actualiza(sensorDataPanel);
        actualiza(buttonsPanel);
        actualiza(sensorDataPanel1);
        actualiza(jPanel5);
        ActuatorsPanel.setVisible(true);
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        jLabel3 = new javax.swing.JLabel();
        roomPanel = new javax.swing.JPanel();
        dataPanel = new javax.swing.JPanel();
        valuedataPanel = new javax.swing.JPanel();
        sensorDataPanel1 = new javax.swing.JPanel();
        sensorDataPanel = new javax.swing.JPanel();
        buttonsPanel = new javax.swing.JPanel();
        roomLabel = new javax.swing.JLabel();
        ActuatorsPanel = new javax.swing.JPanel();
        jLabel2 = new javax.swing.JLabel();
        lightOn = new javax.swing.JButton();
        airOff = new javax.swing.JButton();
        jLabel4 = new javax.swing.JLabel();
        airOn = new javax.swing.JButton();
        sistemDomoticOn = new javax.swing.JButton();
        lightOff = new javax.swing.JButton();
        lumMax = new javax.swing.JTextField();
        tempMax = new javax.swing.JTextField();
        jLabel5 = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        lumMin = new javax.swing.JTextField();
        tempMin = new javax.swing.JTextField();
        jLabel7 = new javax.swing.JLabel();
        jLabel8 = new javax.swing.JLabel();
        controlText = new javax.swing.JLabel();
        sistemDomoticOff = new javax.swing.JButton();
        timeSlider = new javax.swing.JSlider();
        timeLabel = new javax.swing.JLabel();
        taskTime = new javax.swing.JLabel();
        automaticButton = new javax.swing.JButton();
        stopAutomatic = new javax.swing.JButton();
        jPanel2 = new javax.swing.JPanel();
        jPanel6 = new javax.swing.JPanel();
        jPanel5 = new javax.swing.JPanel();
        jPanel3 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        comboRooms = new javax.swing.JComboBox();
        sensorPanel = new javax.swing.JPanel();
        jMenuBar1 = new javax.swing.JMenuBar();
        jMenu1 = new javax.swing.JMenu();
        Cerrar = new javax.swing.JMenuItem();
        jMenu2 = new javax.swing.JMenu();
        jMenu4 = new javax.swing.JMenu();
        jMenu3 = new javax.swing.JMenu();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("Domuticus");
        setResizable(false);

        jPanel1.setBackground(new java.awt.Color(0, 0, 0));

        jLabel3.setIcon(new javax.swing.ImageIcon(getClass().getResource("/img/logo.png"))); // NOI18N
        jLabel3.setText("jLabel3");

        roomPanel.setBackground(new java.awt.Color(0, 0, 0));
        roomPanel.setBorder(javax.swing.BorderFactory.createTitledBorder(new javax.swing.border.LineBorder(new java.awt.Color(204, 204, 0), 1, true), "Room", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("AcmeFont", 0, 12), new java.awt.Color(204, 204, 204))); // NOI18N
        roomPanel.setForeground(new java.awt.Color(255, 255, 255));

        dataPanel.setBackground(new java.awt.Color(0, 0, 0));

        valuedataPanel.setBackground(new java.awt.Color(255, 255, 204));
        valuedataPanel.setBorder(new javax.swing.border.SoftBevelBorder(javax.swing.border.BevelBorder.LOWERED));

        sensorDataPanel1.setBackground(new java.awt.Color(255, 255, 153));

        javax.swing.GroupLayout sensorDataPanel1Layout = new javax.swing.GroupLayout(sensorDataPanel1);
        sensorDataPanel1.setLayout(sensorDataPanel1Layout);
        sensorDataPanel1Layout.setHorizontalGroup(
            sensorDataPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 195, Short.MAX_VALUE)
        );
        sensorDataPanel1Layout.setVerticalGroup(
            sensorDataPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 91, Short.MAX_VALUE)
        );

        sensorDataPanel.setBackground(new java.awt.Color(255, 255, 204));

        javax.swing.GroupLayout sensorDataPanelLayout = new javax.swing.GroupLayout(sensorDataPanel);
        sensorDataPanel.setLayout(sensorDataPanelLayout);
        sensorDataPanelLayout.setHorizontalGroup(
            sensorDataPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 100, Short.MAX_VALUE)
        );
        sensorDataPanelLayout.setVerticalGroup(
            sensorDataPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 0, Short.MAX_VALUE)
        );

        buttonsPanel.setBackground(new java.awt.Color(255, 255, 204));

        javax.swing.GroupLayout buttonsPanelLayout = new javax.swing.GroupLayout(buttonsPanel);
        buttonsPanel.setLayout(buttonsPanelLayout);
        buttonsPanelLayout.setHorizontalGroup(
            buttonsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 154, Short.MAX_VALUE)
        );
        buttonsPanelLayout.setVerticalGroup(
            buttonsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 0, Short.MAX_VALUE)
        );

        javax.swing.GroupLayout valuedataPanelLayout = new javax.swing.GroupLayout(valuedataPanel);
        valuedataPanel.setLayout(valuedataPanelLayout);
        valuedataPanelLayout.setHorizontalGroup(
            valuedataPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(valuedataPanelLayout.createSequentialGroup()
                .addGap(6, 6, 6)
                .addComponent(buttonsPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(sensorDataPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(42, 42, 42)
                .addComponent(sensorDataPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        valuedataPanelLayout.setVerticalGroup(
            valuedataPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(valuedataPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(valuedataPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(sensorDataPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(buttonsPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(sensorDataPanel, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addGap(23, 23, 23))
        );

        roomLabel.setBackground(new java.awt.Color(238, 236, 236));
        roomLabel.setFont(new java.awt.Font("AcmeFont", 0, 14)); // NOI18N
        roomLabel.setForeground(new java.awt.Color(153, 153, 0));

        ActuatorsPanel.setBackground(new java.awt.Color(0, 0, 0));
        ActuatorsPanel.setBorder(javax.swing.BorderFactory.createTitledBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(255, 255, 255)), "Actuadores", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("AcmeFont", 1, 14), java.awt.Color.lightGray)); // NOI18N

        jLabel2.setFont(new java.awt.Font("AcmeFont", 0, 12)); // NOI18N
        jLabel2.setForeground(new java.awt.Color(255, 255, 255));
        jLabel2.setText("Light");

        lightOn.setText("On");
        lightOn.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                lightOnActionPerformed(evt);
            }
        });

        airOff.setText("Off");
        airOff.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                airOffActionPerformed(evt);
            }
        });

        jLabel4.setFont(new java.awt.Font("AcmeFont", 0, 12)); // NOI18N
        jLabel4.setForeground(new java.awt.Color(255, 255, 255));
        jLabel4.setText("Air Conditioning");

        airOn.setText("On");
        airOn.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                airOnActionPerformed(evt);
            }
        });

        sistemDomoticOn.setText("Start System Domotic");
        sistemDomoticOn.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                sistemDomoticOnActionPerformed(evt);
            }
        });

        lightOff.setText("Off");
        lightOff.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                lightOffActionPerformed(evt);
            }
        });

        lumMax.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                lumMaxKeyTyped(evt);
            }
        });

        tempMax.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                tempMaxKeyTyped(evt);
            }
        });

        jLabel5.setForeground(new java.awt.Color(255, 255, 255));
        jLabel5.setText("Valor Temperatura Actuación");

        jLabel6.setForeground(new java.awt.Color(255, 255, 255));
        jLabel6.setText("Valor Luminosidad Actuación");

        lumMin.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                lumMinKeyTyped(evt);
            }
        });

        tempMin.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                tempMinKeyTyped(evt);
            }
        });

        jLabel7.setForeground(new java.awt.Color(255, 255, 255));
        jLabel7.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabel7.setText("MIN");

        jLabel8.setForeground(new java.awt.Color(255, 255, 255));
        jLabel8.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabel8.setText("MAX");

        controlText.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        controlText.setForeground(new java.awt.Color(204, 0, 0));
        controlText.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);

        sistemDomoticOff.setText("Stop System Domotic");
        sistemDomoticOff.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                sistemDomoticOffActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout ActuatorsPanelLayout = new javax.swing.GroupLayout(ActuatorsPanel);
        ActuatorsPanel.setLayout(ActuatorsPanelLayout);
        ActuatorsPanelLayout.setHorizontalGroup(
            ActuatorsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(ActuatorsPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(ActuatorsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addGroup(ActuatorsPanelLayout.createSequentialGroup()
                        .addGroup(ActuatorsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel2)
                            .addComponent(jLabel4))
                        .addGap(34, 34, 34)
                        .addGroup(ActuatorsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(ActuatorsPanelLayout.createSequentialGroup()
                                .addComponent(airOn)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(airOff))
                            .addGroup(ActuatorsPanelLayout.createSequentialGroup()
                                .addComponent(lightOn)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(lightOff))))
                    .addComponent(controlText, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addGroup(ActuatorsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(ActuatorsPanelLayout.createSequentialGroup()
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addGroup(ActuatorsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel6)
                            .addComponent(jLabel5))
                        .addGap(48, 48, 48)
                        .addGroup(ActuatorsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(tempMin)
                            .addComponent(jLabel7, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(lumMin))
                        .addGap(10, 10, 10)
                        .addGroup(ActuatorsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(tempMax)
                            .addComponent(jLabel8, javax.swing.GroupLayout.DEFAULT_SIZE, 48, Short.MAX_VALUE)
                            .addComponent(lumMax)))
                    .addGroup(ActuatorsPanelLayout.createSequentialGroup()
                        .addGap(26, 26, 26)
                        .addComponent(sistemDomoticOn, javax.swing.GroupLayout.PREFERRED_SIZE, 147, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(sistemDomoticOff, javax.swing.GroupLayout.PREFERRED_SIZE, 147, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap())
        );
        ActuatorsPanelLayout.setVerticalGroup(
            ActuatorsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(ActuatorsPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(ActuatorsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel7)
                    .addComponent(jLabel8))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(ActuatorsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2)
                    .addComponent(lightOn)
                    .addComponent(lightOff)
                    .addComponent(lumMax, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(lumMin, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel6))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(ActuatorsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel4)
                    .addComponent(airOn)
                    .addComponent(airOff)
                    .addComponent(tempMax, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(tempMin, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel5))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 8, Short.MAX_VALUE)
                .addGroup(ActuatorsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(sistemDomoticOn, javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(ActuatorsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(controlText, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(sistemDomoticOff))))
        );

        timeSlider.setBackground(new java.awt.Color(0, 0, 0));
        timeSlider.setFont(new java.awt.Font("Tarzan", 0, 3)); // NOI18N
        timeSlider.setForeground(new java.awt.Color(255, 255, 255));
        timeSlider.setMaximum(100000);
        timeSlider.setMinimum(10000);
        timeSlider.setMinorTickSpacing(5000);
        timeSlider.setPaintLabels(true);
        timeSlider.setPaintTicks(true);
        timeSlider.setValue(25000);
        timeSlider.addChangeListener(new javax.swing.event.ChangeListener() {
            public void stateChanged(javax.swing.event.ChangeEvent evt) {
                timeSliderStateChanged(evt);
            }
        });

        timeLabel.setBackground(new java.awt.Color(0, 0, 0));
        timeLabel.setFont(new java.awt.Font("Times New Roman", 0, 12)); // NOI18N
        timeLabel.setForeground(new java.awt.Color(255, 255, 255));

        taskTime.setBackground(new java.awt.Color(0, 0, 0));
        taskTime.setFont(new java.awt.Font("Times New Roman", 0, 12)); // NOI18N
        taskTime.setForeground(new java.awt.Color(255, 0, 0));
        taskTime.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);

        automaticButton.setBackground(new java.awt.Color(240, 200, 242));
        automaticButton.setText("Start Automatic");
        automaticButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                automaticButtonActionPerformed(evt);
            }
        });

        stopAutomatic.setText("Stop Automatic");
        stopAutomatic.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                stopAutomaticActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout dataPanelLayout = new javax.swing.GroupLayout(dataPanel);
        dataPanel.setLayout(dataPanelLayout);
        dataPanelLayout.setHorizontalGroup(
            dataPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(dataPanelLayout.createSequentialGroup()
                .addGroup(dataPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(dataPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                        .addGroup(dataPanelLayout.createSequentialGroup()
                            .addGap(185, 185, 185)
                            .addComponent(taskTime, javax.swing.GroupLayout.PREFERRED_SIZE, 181, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addGap(18, 18, 18)
                            .addComponent(automaticButton)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                            .addComponent(stopAutomatic))
                        .addComponent(roomLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 507, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(dataPanelLayout.createSequentialGroup()
                        .addContainerGap()
                        .addGroup(dataPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(ActuatorsPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addGroup(dataPanelLayout.createSequentialGroup()
                                .addGroup(dataPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(timeSlider, javax.swing.GroupLayout.PREFERRED_SIZE, 111, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(timeLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 175, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(valuedataPanel, javax.swing.GroupLayout.PREFERRED_SIZE, 360, javax.swing.GroupLayout.PREFERRED_SIZE)))))
                .addGap(21, 21, 21))
        );
        dataPanelLayout.setVerticalGroup(
            dataPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, dataPanelLayout.createSequentialGroup()
                .addComponent(roomLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 18, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addGroup(dataPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(valuedataPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(dataPanelLayout.createSequentialGroup()
                        .addComponent(timeSlider, javax.swing.GroupLayout.PREFERRED_SIZE, 72, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(timeLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addGap(23, 23, 23)
                .addGroup(dataPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(dataPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(stopAutomatic, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(automaticButton, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                    .addGroup(dataPanelLayout.createSequentialGroup()
                        .addGap(0, 0, Short.MAX_VALUE)
                        .addComponent(taskTime, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addGap(18, 18, 18)
                .addComponent(ActuatorsPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );

        roomPanel.add(dataPanel);

        jPanel2.setBackground(new java.awt.Color(0, 0, 0));
        jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder(new javax.swing.border.LineBorder(new java.awt.Color(204, 0, 0), 1, true), "Graph", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("AcmeFont", 0, 12), new java.awt.Color(204, 204, 204))); // NOI18N

        jPanel6.setBackground(new java.awt.Color(0, 0, 0));
        jPanel6.setForeground(new java.awt.Color(255, 255, 255));
        jPanel6.setLayout(new java.awt.GridBagLayout());

        jPanel5.setBackground(new java.awt.Color(0, 0, 0));

        javax.swing.GroupLayout jPanel5Layout = new javax.swing.GroupLayout(jPanel5);
        jPanel5.setLayout(jPanel5Layout);
        jPanel5Layout.setHorizontalGroup(
            jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 336, Short.MAX_VALUE)
        );
        jPanel5Layout.setVerticalGroup(
            jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 0, Short.MAX_VALUE)
        );

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel6, javax.swing.GroupLayout.PREFERRED_SIZE, 104, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jPanel5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(20, Short.MAX_VALUE))
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(jPanel5, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jPanel6, javax.swing.GroupLayout.DEFAULT_SIZE, 163, Short.MAX_VALUE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jPanel3.setBackground(new java.awt.Color(0, 0, 0));
        jPanel3.setBorder(javax.swing.BorderFactory.createTitledBorder(new javax.swing.border.LineBorder(new java.awt.Color(255, 255, 255), 1, true), "Options", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("AcmeFont", 0, 12), java.awt.Color.lightGray)); // NOI18N

        jLabel1.setFont(new java.awt.Font("AcmeFont", 0, 14)); // NOI18N
        jLabel1.setForeground(new java.awt.Color(153, 153, 0));
        jLabel1.setText("Select Room :");

        comboRooms.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "<select one item>" }));
        comboRooms.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                comboRoomsItemStateChanged(evt);
            }
        });
        comboRooms.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                comboRoomsActionPerformed(evt);
            }
        });

        sensorPanel.setBackground(new java.awt.Color(0, 0, 0));
        sensorPanel.setBorder(javax.swing.BorderFactory.createTitledBorder(new javax.swing.border.LineBorder(new java.awt.Color(255, 255, 255), 1, true), "Sensors Installed", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("AcmeFont", 0, 11), java.awt.Color.lightGray)); // NOI18N
        sensorPanel.setForeground(new java.awt.Color(255, 255, 255));

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel3Layout.createSequentialGroup()
                        .addGap(33, 33, 33)
                        .addComponent(jLabel1)
                        .addGap(33, 33, 33)
                        .addComponent(comboRooms, javax.swing.GroupLayout.PREFERRED_SIZE, 166, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel3Layout.createSequentialGroup()
                        .addGap(18, 18, 18)
                        .addComponent(sensorPanel, javax.swing.GroupLayout.PREFERRED_SIZE, 359, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(103, Short.MAX_VALUE))
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addGap(20, 20, 20)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(comboRooms, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(48, 48, 48)
                .addComponent(sensorPanel, javax.swing.GroupLayout.PREFERRED_SIZE, 55, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(52, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGap(20, 20, 20)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(jLabel3, javax.swing.GroupLayout.PREFERRED_SIZE, 382, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(52, 52, 52))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(jPanel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                        .addGap(23, 23, 23)
                        .addComponent(roomPanel, javax.swing.GroupLayout.DEFAULT_SIZE, 639, Short.MAX_VALUE)
                        .addContainerGap())))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGap(47, 47, 47)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                    .addComponent(roomPanel, javax.swing.GroupLayout.PREFERRED_SIZE, 463, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 31, Short.MAX_VALUE)
                .addComponent(jLabel3, javax.swing.GroupLayout.PREFERRED_SIZE, 90, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );

        jMenu1.setText("File");

        Cerrar.setText("Cerrar");
        Cerrar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                CerrarActionPerformed(evt);
            }
        });
        jMenu1.add(Cerrar);

        jMenuBar1.add(jMenu1);

        jMenu2.setText("Edit");
        jMenuBar1.add(jMenu2);

        jMenu4.setText("Tools");
        jMenuBar1.add(jMenu4);

        jMenu3.setText("Help");
        jMenuBar1.add(jMenu3);

        setJMenuBar(jMenuBar1);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(1, 1, 1)
                .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGap(37, 37, 37))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    @Override
    public Image getIconImage() {
        Image retValue = Toolkit.getDefaultToolkit().
                getImage(ClassLoader.getSystemResource("img/icono.png"));
        return retValue;
    }

    public String getValue(String sensorType, String room) {
        uc = new MicroControler();
        String value = uc.getCurrentValue(sensorType, room);
        return value;
    }

    private void CerrarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_CerrarActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_CerrarActionPerformed

    private void comboRoomsActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_comboRoomsActionPerformed
    }//GEN-LAST:event_comboRoomsActionPerformed

    private void comboRoomsItemStateChanged(java.awt.event.ItemEvent evt) {

        ejecutaActualiza();
        selectedRoom();

        if (evt.getStateChange() == ItemEvent.SELECTED) {
            if (evt.getItem().toString() == "<select one item>") {
                dataPanel.setVisible(false);
                sensorPanel.setVisible(false);
            } else {
                sensors = getStreams(room);
                addsensorLabelPanel(sensors);
                addPanelDatastream(sensors);
                addgraphLabelPanel(sensors);
                addButtonsPanel(sensors);

                dataPanel.setVisible(true);
                sensorPanel.setVisible(true);

            }
        }

    }

    private void addsensorLabelPanel(List<String> sensors) {

        sensorDataPanel.setLayout(new GridLayout(sensors.size(), 1));

        System.out.println("tamaño lista : " + sensors.size());

        for (int i = 0; i <= sensors.size() - 1; i++) {
            javax.swing.JLabel sensorsName = new JLabel();
            sensorsName.setText(sensors.get(i));
            sensorsName.setForeground(Color.LIGHT_GRAY);
            GridBagConstraints constraints = new GridBagConstraints();
            constraints.fill = GridBagConstraints.HORIZONTAL;
            constraints.gridx = 0; // El área de texto empieza en la columna cero.
            constraints.gridy = i; // El área de texto empieza en la fila cero
            constraints.gridwidth = 1; // El área de texto ocupa dos columnas.
            constraints.gridheight = 1; // El área de texto ocupa 2 filas.

            sensorDataPanel.add(sensorsName);
        }
    }

    private void addgraphLabelPanel(List<String> sensors) {
        jPanel6.setLayout(new GridLayout(sensors.size(), 1));
        jPanel5.setLayout(new GridLayout(sensors.size(), 1));
        //      JScrollPane scroll = new JScrollPane(jPanel5);
        for (int i = 0; i <= sensors.size() - 1; i++) {
            javax.swing.JLabel sensorsName1 = new JLabel();
            javax.swing.JLabel sensorsValue = new JLabel();
            sensorsName1.setText(sensors.get(i));
            sensorsName1.setForeground(Color.LIGHT_GRAY);
            GridBagConstraints constraints = new GridBagConstraints();
            constraints.fill = GridBagConstraints.VERTICAL;
            constraints.fill = GridBagConstraints.HORIZONTAL;
            constraints.gridx = 0; // El área de texto empieza en la columna cero.
            constraints.gridy = i; // El área de texto empieza en la fila cero
            constraints.gridwidth = 1; // El área de texto ocupa dos columnas.
            constraints.gridheight = 1; // El área de texto ocupa 2 filas.
            jPanel6.add(sensorsName1, constraints);

            //sensorsValue.setText("lista : " + i);
            sensorsValue.setForeground(Color.LIGHT_GRAY);




            jPanel5.add(sensorsValue, constraints);


        }

    }

    private void addPanelDatastream(List<String> sensors) {

        roomLabel.setText(room);
        init.setVisible(false);
        for (int i = 0; i <= sensors.size() - 1; i++) {
            javax.swing.JLabel sensorsName = new JLabel();

            sensorsName.setText(sensors.get(i));

            sensorsName.setForeground(Color.LIGHT_GRAY);

            sensorPanel.add(sensorsName);

            if (i < sensors.size() - 1) {
                javax.swing.JLabel separator = new JLabel(" | ");
                separator.setForeground(Color.LIGHT_GRAY);
                sensorPanel.add(separator);
            }
        }
    }

    private void addButtonsPanel(List<String> sensors) {

        buttonsPanel.setLayout(new GridLayout(sensors.size(), 1));
        sensorDataPanel1.setLayout(new GridLayout(sensors.size(), 1));
        final String listas[] = new String[sensors.size()];
        for (int i = 0; i <= sensors.size() - 1; i++) {
            javax.swing.JButton sensorsName1 = new JButton();
            javax.swing.JLabel sensorLabelValue = new JLabel();
            sensorsName1.setActionCommand(sensors.get(i));
            ActionListener ac = new ActionListener() {
                @Override
                public void actionPerformed(ActionEvent e) {

                    sensorType = e.getActionCommand();
                    Component[] list = jPanel5.getComponents();
                    Component[] num = buttonsPanel.getComponents();
                    for (int j = 0; j <= num.length - 1; j++) {

                        javax.swing.JLabel sensorLabelValue = new JLabel();
                        sensorLabelValue.setName(num[j].getName());
                        String value;
                        if (num[j].getName().equals(e.getActionCommand())) {
                            value = getValue(sensorType, selectedRoom());
                            sensorLabelValue.setText(value);
                            if (listas[j] == null) {
                                listas[j] = "";
                            }
                            if (value.length() < 7) {
                                for (int i = 0; i < (7 - value.length()); i++) {
                                    value += "  ";
                                }
                            }
                            listas[j] = value + ",  " + listas[j];
                            sensorDataPanel1.add(sensorLabelValue, j);
                            sensorDataPanel1.remove(sensorDataPanel1.getComponent(j + 1));
                            sensorDataPanel1.updateUI();
                            if (listas[j] != null) {
                                javax.swing.JLabel text = (javax.swing.JLabel) list[j];
                                text.setForeground(Color.GREEN);

                                //text.setScrollOffset(jPanel5.getY());
                                text.setText(listas[j]);

                                jPanel5.updateUI();
                            }

                            if (listas[j].length() > 54) {
                                listas[j] = "   ";
                            }
                        }
                    }
                }
            };

            sensorsName1.addActionListener(ac);
            sensorsName1.setText("Get " + sensors.get(i));
            sensorsName1.setName(sensors.get(i));
            sensorLabelValue.setName(sensors.get(i));
            sensorsName1.setForeground(Color.DARK_GRAY);
            GridBagConstraints constraints = new GridBagConstraints();
            constraints.gridx = 0; // El área de texto empieza en la columna cero.
            constraints.gridy = i; // El área de texto empieza en la fila cero
            constraints.gridwidth = 1; // El área de texto ocupa dos columnas.
            constraints.gridheight = 1; // El área de texto ocupa 2 filas.
            buttonsPanel.add(sensorsName1, constraints);
            sensorDataPanel1.add(sensorLabelValue);

        }

    }

    private void automaticButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_automaticButtonActionPerformed
        timeCopia = time / 1000;
        timetask = new Timer(1000, new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                //taskTime.setText(timer.getDelay()/1000 + " s");
                taskTime.setText("Tiempo restante " + timeCopia + " s");
                timeCopia--;
            }
        });
        timer = new Timer(time, new ActionListener() {
            Integer numBotones = buttonsPanel.getComponentCount();
            javax.swing.JButton[] botones = new javax.swing.JButton[numBotones];

            @Override
            public void actionPerformed(ActionEvent e) {
                for (int i = 0; i <= numBotones - 1; i++) {
                    botones[i] = (javax.swing.JButton) buttonsPanel.getComponent(i);
                    botones[i].doClick();

                }
                timetask.start();
                timeCopia = time / 1000;
            }
        });
        timer.setInitialDelay(0);
        timer.start();
        automaticButton.setEnabled(false);
        timeSlider.setEnabled(false);

    }//GEN-LAST:event_automaticButtonActionPerformed

    private void stopAutomaticActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_stopAutomaticActionPerformed
        timer.stop();
        timetask.stop();
        automaticButton.setEnabled(true);
//        getTemperature.setEnabled(true);
//        getLuminosity.setEnabled(true);
        //    getHumidity.setEnabled(true);
        timeSlider.setEnabled(true);
    }//GEN-LAST:event_stopAutomaticActionPerformed

    private void timeSliderStateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_timeSliderStateChanged
        time = timeSlider.getValue();
        timeLabel.setText("Actualizacion de datos cada " + time / 1000 + " s");
    }//GEN-LAST:event_timeSliderStateChanged

    private void sistemDomoticOnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_sistemDomoticOnActionPerformed
        controlText.setText("");
        if (checkTextLabel()) {

            controlText.setText("System Domotic Activated");
            lightOn.setEnabled(false);
            lightOff.setEnabled(false);
            airOn.setEnabled(false);
            airOff.setEnabled(false);
            sistemDomoticOn.setEnabled(false);
            Double tMin = Double.parseDouble(tempMin.getText());
            Double tMax = Double.parseDouble(tempMin.getText());
            Double lMin = Double.parseDouble(lumMin.getText());
            Double lMax = Double.parseDouble(lumMax.getText());
            uc.startDomiticSystem(tMin, tMax, lMin, lMax);


        }
    }//GEN-LAST:event_sistemDomoticOnActionPerformed

    private void lumMinKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_lumMinKeyTyped
        controlText.setText("");
        char car = evt.getKeyChar();
        if (lumMin.getText().length() > 1) {
            controlText.setText("Only two numbers");
            evt.consume();
        }
        if ((car < '0' || car > '9')) {
            controlText.setText("Only type numbers");
            evt.consume();
        }
    }//GEN-LAST:event_lumMinKeyTyped

    private void lumMaxKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_lumMaxKeyTyped
        controlText.setText("");
        char car = evt.getKeyChar();
        if (lumMax.getText().length() > 1) {
            controlText.setText("Only two numbers");
            evt.consume();
        }
        if ((car < '0' || car > '9')) {
            controlText.setText("Only type numbers");
            evt.consume();
        }
    }//GEN-LAST:event_lumMaxKeyTyped

    private void tempMinKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_tempMinKeyTyped
        controlText.setText("");
        char car = evt.getKeyChar();
        if (tempMin.getText().length() > 1) {
            controlText.setText("Only two numbers");
            evt.consume();
        }
        if ((car < '0' || car > '9')) {
            controlText.setText("Only type numbers");
            evt.consume();
        }
    }//GEN-LAST:event_tempMinKeyTyped

    private void tempMaxKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_tempMaxKeyTyped
        controlText.setText("");
        char car = evt.getKeyChar();
        if (tempMax.getText().length() > 1) {
            controlText.setText("Only two numbers");
            evt.consume();
        }

        if ((car < '0' || car > '9')) {
            controlText.setText("Only type numbers");
            evt.consume();
        }
    }//GEN-LAST:event_tempMaxKeyTyped

    private void sistemDomoticOffActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_sistemDomoticOffActionPerformed
        controlText.setText("Domotic System Shut down");
        lightOn.setEnabled(true);
        lightOff.setEnabled(true);
        airOn.setEnabled(true);
        airOff.setEnabled(true);
        sistemDomoticOn.setEnabled(true);
        uc.stopDomoticSystem();
        

    }//GEN-LAST:event_sistemDomoticOffActionPerformed

    private void lightOnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_lightOnActionPerformed
        uc.activateLight();
    }//GEN-LAST:event_lightOnActionPerformed

    private void airOnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_airOnActionPerformed
        uc.activateAir();
    }//GEN-LAST:event_airOnActionPerformed

    private void lightOffActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_lightOffActionPerformed
        uc.lightOFF();
    }//GEN-LAST:event_lightOffActionPerformed

    private void airOffActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_airOffActionPerformed
        uc.airOFF();
    }//GEN-LAST:event_airOffActionPerformed
    private Boolean checkTextLabel() {
        Boolean check = true;
        if (tempMin.getText().isEmpty() || tempMax.getText().isEmpty()
                || lumMin.getText().isEmpty() || lumMax.getText().isEmpty()) {
            controlText.setText("Debe introducir todos los valores");
            check = false;
        }
        else if (Double.parseDouble(tempMin.getText()) >= Double.parseDouble(tempMax.getText())) {
            controlText.setText("Temperature max must be higher than min");
            tempMin.setText("");
            tempMax.setText("");
            check = false;


        }
        else if (Double.parseDouble(lumMin.getText()) >= Double.parseDouble(lumMax.getText())) {
            controlText.setText("Luminosity max must be higher than min");
            lumMin.setText("");
            lumMax.setText("");
            check = false;


        }

        return check;
    }

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(VentanaPrincipal.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(VentanaPrincipal.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(VentanaPrincipal.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(VentanaPrincipal.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new VentanaPrincipal().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JPanel ActuatorsPanel;
    private javax.swing.JMenuItem Cerrar;
    private javax.swing.JButton airOff;
    private javax.swing.JButton airOn;
    private javax.swing.JButton automaticButton;
    private javax.swing.JPanel buttonsPanel;
    private javax.swing.JComboBox comboRooms;
    private javax.swing.JLabel controlText;
    private javax.swing.JPanel dataPanel;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JMenu jMenu1;
    private javax.swing.JMenu jMenu2;
    private javax.swing.JMenu jMenu3;
    private javax.swing.JMenu jMenu4;
    private javax.swing.JMenuBar jMenuBar1;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPanel jPanel5;
    private javax.swing.JPanel jPanel6;
    private javax.swing.JButton lightOff;
    private javax.swing.JButton lightOn;
    private javax.swing.JTextField lumMax;
    private javax.swing.JTextField lumMin;
    private javax.swing.JLabel roomLabel;
    private javax.swing.JPanel roomPanel;
    private javax.swing.JPanel sensorDataPanel;
    private javax.swing.JPanel sensorDataPanel1;
    private javax.swing.JPanel sensorPanel;
    private javax.swing.JButton sistemDomoticOff;
    private javax.swing.JButton sistemDomoticOn;
    private javax.swing.JButton stopAutomatic;
    private javax.swing.JLabel taskTime;
    private javax.swing.JTextField tempMax;
    private javax.swing.JTextField tempMin;
    private javax.swing.JLabel timeLabel;
    private javax.swing.JSlider timeSlider;
    private javax.swing.JPanel valuedataPanel;
    // End of variables declaration//GEN-END:variables
}
